#ifndef CONVERSE_MESSAGECONTAINER_H
#define CONVERSE_MESSAGECONTAINER_H


#include <QObject>
#include <QMutex>


namespace Converse {

class AbstractMessage;
class AbstractDataItem;
class MessageGroup;

class MessageContainer : public QObject
{
    Q_OBJECT
public:
    typedef QList<AbstractDataItem *> MessageItemList;

public:
    explicit MessageContainer(QObject *parent = 0);
    virtual ~MessageContainer();

private:
    mutable QMutex m_mutex;
    QList<MessageGroup *> m_dataItemList;

Q_SIGNALS:
    void dataAboutToBeInserted(int index, MessageGroup *messageGroup);
    void dataInserted(int index, MessageGroup *messageGroup);

    void dataAboutToBeUpdated(int index, MessageGroup *messageGroup);
    void dataUpdated(int index, MessageGroup *messageGroup);

private:
    void itemAboutToBeInserted(int index, MessageGroup *messageGroup);
    void itemInserted(int index, MessageGroup *messageGroup);
    void itemAboutToBeUpdated(int index, MessageGroup *messageGroup);
    void itemUpdated(int index, MessageGroup *messageGroup);

private:
    void insertItem(int index, MessageGroup *messageGroup);
    void appendItem(MessageGroup *messageGroup);
    void updateItem(AbstractMessage *message, MessageGroup *messageGroup);

public:
    const QList<MessageGroup *> &dataItemList() const;

public:
    int insert(AbstractMessage *message);
    void insert(MessageGroup *messageGroup);

    void append(AbstractMessage *message);
    void append(MessageGroup *messageGroup);

public:
    bool contains(MessageGroup *messageGroup) const;
    bool validIndex(int index) const;
    MessageGroup *at(int index) const;
    int indexOf(MessageGroup *messageGroup) const;
    int count() const;
    int size() const;
};

} // namespace Converse

#endif // CONVERSE_MESSAGECONTAINER_H
